# service/predictor_service.py

from typing import Dict, Any
from model.predictor import ModelPredictor
from config.features import FEATURE_SETS

predictor = ModelPredictor()

def predict_by_model(model_name: str, features: Dict[str, float]) -> Dict[str, Any]:
    if model_name not in FEATURE_SETS:
        raise ValueError(f"❌ 模型名不合法: {model_name}")

    required_fields = FEATURE_SETS[model_name]
    missing = [field for field in required_fields if field not in features]
    if missing:
        raise ValueError(f"❌ 缺少必要字段: {missing}")

    return predictor.predict_from_dict(model_name, features)
